package com.ruoyi.web.controller.tourism;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TravelGuide;
import com.ruoyi.system.service.ITravelGuideService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 攻略Controller
 *
 * @author Y.C
 * @date 2024-02-21
 */
@RestController
@RequestMapping("/system/guide")
public class TravelGuideController extends BaseController
{
    @Autowired
    private ITravelGuideService travelGuideService;

    /**
     * 查询攻略列表
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(TravelGuide travelGuide)
    {
        startPage();
        List<TravelGuide> list = travelGuideService.selectTravelGuideList(travelGuide);
        return getDataTable(list);
    }

    /**
     * 导出攻略列表
     */
    @Anonymous

    @PostMapping("/export")
    public void export(HttpServletResponse response, TravelGuide travelGuide)
    {
        List<TravelGuide> list = travelGuideService.selectTravelGuideList(travelGuide);
        ExcelUtil<TravelGuide> util = new ExcelUtil<TravelGuide>(TravelGuide.class);
        util.exportExcel(response, list, "攻略数据");
    }

    /**
     * 获取攻略详细信息
     */
    @Anonymous
    @GetMapping(value = "/{strategyId}")
    public AjaxResult getInfo(@PathVariable("strategyId") Long strategyId)
    {
        return success(travelGuideService.selectTravelGuideByStrategyId(strategyId));
    }

    /**
     * 新增攻略
     */
    @Anonymous

    @PostMapping
    public AjaxResult add(@RequestBody TravelGuide travelGuide)
    {
        return toAjax(travelGuideService.save(travelGuide));
    }

    /**
     * 修改攻略
     */
    @Anonymous

    @PutMapping
    public AjaxResult edit(@RequestBody TravelGuide travelGuide)
    {
        return toAjax(travelGuideService.updateById(travelGuide));
    }

    /**
     * 删除攻略
     */
    @Anonymous

	@DeleteMapping("/{strategyIds}")
    public AjaxResult remove(@PathVariable Long[] strategyIds)
    {
        return toAjax(travelGuideService.removeByIds(Arrays.asList(strategyIds)));
    }
}
